//
//  MPFNavigationItem.m
//  导航栏定制
//
//  Created by LG on 2017/11/24.
//  Copyright © 2017年 my. All rights reserved.
//

#import "MPFNavigationItem.h"

@implementation MPFNavigationCenterItem

+ (instancetype)navigationCenterItemView:(UIView *)centerView size:(CGSize)size {
    MPFNavigationCenterItem *item = [self new];
    item.centerView = centerView;
    item.centerViewSize = size;
    
    return item;
}

@end

@implementation MPFNavigationItem

+ (instancetype)actionWithContent:(NSString*)content
                             info:(NSDictionary*)info
                            style:(MPFNavigationItemStyle)style
                          handler:(MPFNavigationAction)handler {
    MPFNavigationItem *item = [self new];
    item.content = content;
    item.info = info;
    item.style = style;
    item.handler = [handler copy];
    return item;
}

+ (instancetype)actionWithContentView:(UIView*)contentView
                                 info:(NSDictionary*)info
                              handler:(MPFNavigationAction)handler
{
    MPFNavigationItem *item = [self new];
    item.customView = contentView;
    item.info = info;
    item.handler = [handler copy];
    return item;
}

+ (instancetype)actionSpaceinfo:(NSDictionary*)info
                     spaceWidth:(CGFloat)spaceWidth {
    MPFNavigationItem *item = [self new];
    item.content = nil;
    item.info = info;
    item.style = MPFNavigationItemStyleSpace;
    item.handler = nil;
    return item;
}

+ (UIView *)customViewWithSize:(CGSize)size image:(UIImage*)img
{
    if ([img isKindOfClass:[UIImage class]]) {
        UIImageView *imgView = [[UIImageView alloc]initWithImage:img];
        if (!CGSizeEqualToSize(size, CGSizeZero)) {
            return imgView;
        } else {
            CGSize imgSize = img.size;
            size = CGSizeMake(MAX(imgSize.width, size.width), MAX(imgSize.height, size.height));
            UIView *view = [[UIView alloc]initWithFrame:CGRectMake(0, 0, size.width, size.height)];
            imgView.frame = CGRectMake((size.width - imgSize.width)/2.,
                                       (size.height - imgSize.height)/2., imgSize.width, imgSize.height);
            [view addSubview:imgView];
            view.userInteractionEnabled = NO;
            
            return view;
        }
    }
    
    return [UIView new];
}

@end
